<?php

namespace app\admin\controller;

use app\admin\model\Admin;
use app\admin\model\User;
use app\common\controller\Backend;
use app\common\model\Attachment;
use fast\Date;
use think\Db;

/**
 * 打印机管理
 *
 * @icon   fa fa-dashboard
 * @remark 用于展示打印机的设置、调试等
 */
class Printer extends Backend
{

    protected $model = null;
    protected $noNeedRight = [];

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('app\common\model\Printer');
        // $this->view->assign("mimetypeList", \app\common\model\Attachment::getMimetypeList());
        // $this->view->assign("categoryList", \app\common\model\Attachment::getCategoryList());
        // $this->assignconfig("categoryList", \app\common\model\Attachment::getCategoryList());
    }

    /**
     * 编辑
     */
    public function edit($ids = null)
    {
        $row = $this->model->get($ids);
        if (!$row) {
            $this->error(__('No Results were found'));
        }
        if ($this->request->isPost()) {
            $this->token();

            // 更新
            $params = $this->request->post("row/a");
            
            if ($params) {
                $params = $this->preExcludeFields($params);

                try {
                    $result = $row->allowField(true)->save($params);
                    if ($result !== false) {
                        $this->success();
                    } else {
                        $this->error($row->getError());
                    }
                } catch (\think\exception\PDOException $e) {
                    $this->error($e->getMessage());
                } catch (\think\Exception $e) {
                    $this->error($e->getMessage());
                }
            }
            $this->error(__('Parameter %s can not be empty', ''));
        }

        $this->view->assign("row", $row);
        return $this->view->fetch();
    }
}
